package com.beans;

import java.util.Collections;
import java.util.Stack;

import com.beans.Card.Rank;
import com.beans.Card.Suit;
import com.dao.CardModel;

/*Models a deck of 52 cards (no joker).*/
public class Deck 
{
	private Stack<Card> aCards;
	
	/*Creates a new deck of 52 cards, not shuffled.*/
	public Deck()
	{
		aCards = new Stack<Card>();
		reset();
	}
	
	private void reset()
	{
		aCards.clear();
		for( Suit lSuit : Suit.values() )
		{
            for( Rank lRank : Rank.values() )
            {
                aCards.add( new Card( lRank, lSuit ));
            }
		}
	}

    public boolean distribute(long userId, long roundId)
    {
    	Card card = aCards.pop();
    	CardModel cardM = new CardModel();
    	cardM.addCard(card, userId, roundId);
    	
        return true;
    }

	/*Shuffle the deck of cards by retreiving all 52 cards and randomizing their order. */
	public void shuffle()
	{
		reset();
		Collections.shuffle( aCards );
	}

	/*Returns The number of cards in the deck. */
	public int size()
	{
		return aCards.size();
	}
}
